import React from 'react';

function guard(App, whiteList= ["/","/home","/login","/register"]){
    const checkWhiteList = (props, _this)=>{
        if(whiteList.findIndex(it => it === props.location.pathname)<0){
            if(!localStorage.getItem("ReactProjectLoginUser"))
                _this.props.history.push("/login");
        }
    }
    class GuardApp extends React.Component{
        componentDidMount(){ checkWhiteList(this.props, this) }
        componentDidUpdate(){  checkWhiteList(this.props,this) }
        render(){ return <App {...this.props} /> }
    }
    return GuardApp;
}
export default guard;

/* 构建守卫: 支持传入白名单
        const whiteList = ["/login","/","/home"];
    export default withRouter(gurad(App,whiteList));
*/
